<?php
  class Admin_m extends Model{
      function Admin_m(){
          parent::Model();
          $this->load->database();
      }
     function login($username, $password){
     	  $query= $this->db->get_where('admin',array('ident'=>$username,'pass'=>$password));
     	    return $query;
     }
      function get_admin($per_page,$offset){
     	  $this->db->select();
     	  $this->db->from('admin');
     	  $this->db->limit($per_page,$offset);
     	  $query=$this->db->get();
     	    return $query->result_array();
     }
     
      function get_animaux($per_page,$offset){
     	  $this->db->select('animaux.*,categories.nom as catnom');
     	  $this->db->from('animaux');
     	  $this->db->join('categories', 'categories.id = animaux.catid');
     	  $this->db->limit($per_page,$offset);
     	  $query=$this->db->get();
     	    return $query->result_array();
     }
     function delete_admin($id){
         return $this->db->delete('admin',array('id'=>$id));  
     }
     function is_name_existe($name){
             $query = $this->db->get_where('admin', array('ident'=>$name));
             if ($query->num_rows()>0){ return true;}
            return false;
     }
     function is_password($pass,$idadmin){
          $query = $this->db->get_where('admin', array('id'=>$idadmin,'pass'=>$pass));
             if ($query->num_rows()>0){ return true;}
            return false;
     }
     function add_admin($data){
         $query= $this->db->insert('admin',$data);
            return $query;
     }
     function get_detail_admin($id){
        $query = $this->db->get_where('admin', array('id'=>$id));  
        return $query->row_array();  
     }
     function update_admin($data,$idadmin){
          return $this->db->update('admin',$data,array('id'=>$idadmin));
     }
  }
?>
